package com.huilian.iotbox.admin.wap.controller;

import com.huilian.iotbox.admin.wap.service.PermissionService;
import com.huilian.iotbox.data.common.ServerResponse;
import com.huilian.iotbox.data.dto.RolePermissionTempDto;
import com.huilian.iotbox.data.enums.RoleEnum;
import com.huilian.iotbox.data.vo.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author LinYinDong
 * @date 2024/10/9 下午5:17
 */
@RestController
@RequestMapping("/api/permission")
public class PermissionController extends UserInfoController {
    @Autowired
    private PermissionService permissionService;

    @GetMapping("/findPermissionList")
    public ServerResponse findPermissionList(HttpServletRequest request, RolePermissionTempDto rolePermissionTempDto) {
        final UserInfo userInfo = super.getLoginUserInfo(request);
        rolePermissionTempDto.setUserInfo(userInfo);
        return permissionService.findPermissionList(rolePermissionTempDto);
    }

    @PostMapping("/roleEchoSwitch")
    public ServerResponse roleEchoSwitch(HttpServletRequest request, @RequestBody RolePermissionTempDto rolePermissionTempDto) {
        UserInfo userInfo = super.getLoginUserInfo(request);
        rolePermissionTempDto.setUserInfo(userInfo);
        return permissionService.roleEchoSwitch(rolePermissionTempDto);
    }
}
